---
title: 'Replication file: Negative Political Identities and Costly Political Action: Appendix Section A.12'
author: "Katharina Lawall, Stuart J Turnbull-Dugarte, Florian Foos \& Josh Townsley"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
  pdf_document: default
  bookdown::pdf_document2:
    toc: false
    keep_tex: yes
    latex_engine: xelatex
abstract:
  
keywords: 
mainfont: cochineal
fontsize: 11pt
---


<!-- Set your working directory here -->
```{r setup, include=FALSE, cache = FALSE}
#install.packages("knitr")
rm(list=ls())
require("knitr")
#knitr::opts_knit$set(root.dir = "C:/Users/katharina.lawall/Downloads/NegativePoliticalIdentities")

```


<!--Load all the required libraries in -->

```{r libraries, include=FALSE, cache = FALSE}

library(margins)

library(haven)
library(estimatr)
library(texreg)
library(dplyr)
library(tidyr)
library(forcats)
library(viridisLite)
library(ggplot2)
library(stringr)
library(randomizr)
library(estimatr)

library(purrr)
library(ggpubr)
library(patchwork)

library(stargazer)

library(jtools)

#install.packages("jtools")

colors <- viridis(option = "magma", 
                  begin = 0.1, 
                  end = .8, 
                  direction = -1, 
                  n = 4)

```

<!--Loading in survey data -->

```{r dataload, , echo=FALSE}

##Data from: https://www.britishelectionstudy.com/data-object/wave-19-of-the-2014-2023-british-election-study-internet-panel/
BES19 <- read_dta("data/BES2019_W19.dta")

BES19<- BES19 %>% 
  mutate(brexitID= case_when(
                            euID == 1 ~ "Yes",
                            euID == 2 ~ "Yes",
                            euID == 3 ~ "No",
                            euID == 9999 ~ "No"))

BES19<- BES19 %>% 
  mutate(partyID= if_else(partyId < 10, "Yes", "No"))

BES19$partyID[BES19$partyId == 12] <- "Yes"

df<- subset(BES19, (brexitID!=""))

df<- df %>% 
  mutate(euRefDoOver=as.factor(euRefDoOver),
         euRefVote=as.factor(euRefVote))
df$euRefDoOver <- factor(df$euRefDoOver,
                   levels = c(0,1, 9999),
                   labels = c("No", "Yes", "Don't know"))
df$euRefVote <- factor(df$euRefVote,
                         levels = c(0,1,2, 9999),
                         labels = c("Remain", "Leave", "Would not vote","Don't know"))
         
df<- df %>% 
  mutate(doubleID= case_when(
    brexitID == "No" &  partyID == "No" ~ "Has no identity",
    brexitID == "No" &  partyID == "Yes" ~ "Has party identity only",
    brexitID == "Yes" &  partyID == "No" ~ "Has Brexit identity only",
    brexitID == "Yes" &  partyID == "Yes" ~ "Has both identities"))

Cons<- subset(df, (p_past_vote_2019==1))
Lab<- subset(df, (p_past_vote_2019==2))
LDs<- subset(df, (p_past_vote_2019==3))
Greens<- subset(df, (p_past_vote_2019==7))

```


# Figure A9.A

```{r figurea9a, echo=F}
plot1<- df %>%
  ggplot(aes(x = fct_infreq(brexitID), fill=brexitID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Has a Brexit identity?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

plot2<- df %>%
  ggplot(aes(x = fct_infreq(partyID), fill=partyID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("")+
  xlab("")+
  ggtitle("Has a party identity?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))


plot3<- df %>%
  ggplot(aes(x = fct_infreq(doubleID), fill=doubleID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format())+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Has both identities?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

(plot1+plot2)/plot3+
  plot_annotation(title = "Prevalence of party & issue identities in Britain (December 2019)",
                  caption = "Data: British Election Study Internal Panel Wave 19 (N=7909)",
                  theme=theme(plot.title=element_text(size = 16, face="bold", hjust=0)))
ggsave("output/FigureA9a.png", width =24, height = 19, units = "cm", dpi=600)

```





# Figure A9.B


```{r figurea9b, echo=F, warning=F}




plot1<- LDs %>%
  ggplot(aes(x = fct_infreq(brexitID), fill=brexitID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Has a Brexit identity?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

plot2<- LDs %>%
  ggplot(aes(x = fct_infreq(partyID), fill=partyID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("")+
  xlab("")+
  ggtitle("Has a party identity?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))


plot3<- LDs %>%
  ggplot(aes(x = fct_infreq(doubleID), fill=doubleID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format())+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Has both identities?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

(plot1+plot2)/plot3+
  plot_annotation(title = "Prevalence of party & issue identities among\n2019 Liberal Democrat voters (December 2019)",
                  caption = "Data: British Election Study Internal Panel Wave 19 (N=839)",
                  theme=theme(plot.title=element_text(size = 16, face="bold", hjust=0)))
ggsave("output/FigureA9b.png", width =24, height = 19, units = "cm", dpi=600)


```


# Figure A9.C



```{r figurea9c, echo=F, warning=F}




plot1<- Lab %>%
  ggplot(aes(x = fct_infreq(brexitID), fill=brexitID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Has a Brexit identity?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

plot2<- Lab %>%
  ggplot(aes(x = fct_infreq(partyID), fill=partyID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("")+
  xlab("")+
  ggtitle("Has a party identity?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))


plot3<- Lab %>%
  ggplot(aes(x = fct_infreq(doubleID), fill=doubleID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format())+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Has both identities?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

(plot1+plot2)/plot3+
  plot_annotation(title = "Prevalence of party & issue identities among\n2019 Labour voters (December 2019)",
                  caption = "Data: British Election Study Internal Panel Wave 19 (N=2098)",
                  theme=theme(plot.title=element_text(size = 16, face="bold", hjust=0)))
ggsave("output/FigureA9c.png", width =24, height = 19, units = "cm", dpi=600)


```


# Figure A9.D



```{r figurea9d, echo=F, warning=F}


plot1<- Cons %>%
  ggplot(aes(x = fct_infreq(brexitID), fill=brexitID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Has a Brexit identity?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

plot2<- Cons %>%
  ggplot(aes(x = fct_infreq(partyID), fill=partyID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("")+
  xlab("")+
  ggtitle("Has a party identity?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))


plot3<- Cons %>%
  ggplot(aes(x = fct_infreq(doubleID), fill=doubleID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format())+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Has both identities?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

(plot1+plot2)/plot3+
  plot_annotation(title = "Prevalence of party & issue identities among\n2019 Conservative voters (December 2019)",
                  caption = "Data: British Election Study Internal Panel Wave 19 (N=3173)",
                  theme=theme(plot.title=element_text(size = 16, face="bold", hjust=0)))
ggsave("output/FigureA9d.png", width =24, height = 19, units = "cm", dpi=600)




```


# Figure A10.A


```{r figurea10a, echo=F, warning=F}

PV_Cons<- Cons %>%
  ggplot(aes(x = fct_infreq(euRefDoOver), fill=euRefDoOver)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Conservative voters")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

PV_Lab<- Lab %>%
  ggplot(aes(x = fct_infreq(euRefDoOver), fill=euRefDoOver)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Labour voters")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

PV_LDs<- LDs %>%
  ggplot(aes(x = fct_infreq(euRefDoOver), fill=euRefDoOver)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Liberal Democrat voters")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

PV_Gr<- Greens %>%
  ggplot(aes(x = fct_infreq(euRefDoOver), fill=euRefDoOver)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Green party voters")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

(PV_Cons+PV_Lab)/(PV_LDs+PV_Gr)+
  plot_annotation(title = "Proportion of voters who support a second referendum\n(December 2019)",
                  caption = "Data: British Election Study Internal Panel Wave 19",
                  theme=theme(plot.title=element_text(size = 16, face="bold", hjust=0)))
ggsave("output/FigureA10a.png", width =24, height = 19, units = "cm", dpi=600)

```

# Figure A10.B


```{r figurea10b, echo=F, warning=F}


VI_Cons<- Cons %>%
  ggplot(aes(x = fct_infreq(euRefVote), fill=euRefVote)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Conservative voters")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

VI_Lab<- Lab %>%
  ggplot(aes(x = fct_infreq(euRefVote), fill=euRefVote)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Labour voters")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

VI_LDs<- LDs %>%
  ggplot(aes(x = fct_infreq(euRefVote), fill=euRefVote)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Liberal Democrat voters")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

VI_Gr<- Greens %>%
  ggplot(aes(x = fct_infreq(euRefVote), fill=euRefVote)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Green party voters")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

(VI_Cons+VI_Lab)/(VI_LDs+VI_Gr)+
  plot_annotation(title = "Vote intentions in hypothetical second referendum\n(December 2019)",
                  caption = "Data: British Election Study Internal Panel Wave 19",
                  theme=theme(plot.title=element_text(size = 16, face="bold", hjust=0)))
ggsave("output/FigureA10b.png", width =24, height = 19, units = "cm", dpi=600)


```

```{r figurea11dataload, echo=F, warning=F}

##Prevalence of issue and party identities in most recent wave of the BES (May 2022)##
##Data from: https://www.britishelectionstudy.com/data-object/wave-23-of-the-2014-2023-british-election-study-internet-panel/
BES22 <- read_dta("data/BES2019_W23.dta")
BES22<- BES22 %>% 
  mutate(brexitID= case_when(
    euID == 1 ~ "Yes",
    euID == 2 ~ "Yes",
    euID == 3 ~ "No",
    euID == 9999 ~ "No"))

BES22<- BES22 %>% 
  mutate(partyID= if_else(partyId < 10, "Yes", "No"))
BES22$partyID[BES22$partyId == 12] <- "Yes"
df22<- subset(BES22, (brexitID!=""))

df22<- df22 %>% 
  mutate(doubleID= case_when(
    brexitID == "No" &  partyID == "No" ~ "Has no identity",
    brexitID == "No" &  partyID == "Yes" ~ "Has party identity only",
    brexitID == "Yes" &  partyID == "No" ~ "Has Brexit identity only",
    brexitID == "Yes" &  partyID == "Yes" ~ "Has both identities"))

Cons22<- subset(df22, (p_past_vote_2019==1))
Lab22<- subset(df22, (p_past_vote_2019==2))
LDs22<- subset(df22, (p_past_vote_2019==3))

```

# Figure A11.A

```{r figurea11A, echo=F, warning=F}


plot1<- df22 %>%
  ggplot(aes(x = fct_infreq(brexitID), fill=brexitID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Has a Brexit identity?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

plot2<- df22 %>%
  ggplot(aes(x = fct_infreq(partyID), fill=partyID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("")+
  xlab("")+
  ggtitle("Has a party identity?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))


plot3<- df22 %>%
  ggplot(aes(x = fct_infreq(doubleID), fill=doubleID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format())+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Has both identities?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

(plot1+plot2)/plot3+
  plot_annotation(title = "Prevalence of party & issue identities in Britain (May 2022)",
                  caption = "Data: British Election Study Internal Panel Wave 23 (N=30,949)",
                  theme=theme(plot.title=element_text(size = 16, face="bold", hjust=0)))
ggsave("output/FigureA11a.png", width =24, height = 19, units = "cm", dpi=600)



```


# Figure A11.B

```{r figurea11b, echo=F, warning=F}

plot1<- LDs22 %>%
  ggplot(aes(x = fct_infreq(brexitID), fill=brexitID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Has a Brexit identity?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

plot2<- LDs22 %>%
  ggplot(aes(x = fct_infreq(partyID), fill=partyID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("")+
  xlab("")+
  ggtitle("Has a party identity?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))


plot3<- LDs22 %>%
  ggplot(aes(x = fct_infreq(doubleID), fill=doubleID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format())+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Has both identities?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

(plot1+plot2)/plot3+
  plot_annotation(title = "Prevalence of party & issue identities among\n2019 Liberal Democrat voters (May 2022)",
                  caption = "Data: British Election Study Internal Panel Wave 23 (N=3363)",
                  theme=theme(plot.title=element_text(size = 16, face="bold", hjust=0)))
ggsave("output/FigureA11b.png", width =24, height = 19, units = "cm", dpi=600)



```
# Figure A11.C

```{r figurea11c, echo=F, warning=F}
plot1<- Lab22 %>%
  ggplot(aes(x = fct_infreq(brexitID), fill=brexitID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Has a Brexit identity?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

plot2<- Lab22 %>%
  ggplot(aes(x = fct_infreq(partyID), fill=partyID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("")+
  xlab("")+
  ggtitle("Has a party identity?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))


plot3<- Lab22 %>%
  ggplot(aes(x = fct_infreq(doubleID), fill=doubleID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format())+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Has both identities?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

(plot1+plot2)/plot3+
  plot_annotation(title = "Prevalence of party & issue identities among\n2019 Labour voters (May 2022)",
                  caption = "Data: British Election Study Internal Panel Wave 23 (N=8040)",
                  theme=theme(plot.title=element_text(size = 16, face="bold", hjust=0)))
ggsave("output/FigureA11c.png", width =24, height = 19, units = "cm", dpi=600)


```


# Figure A11.D

```{r figurea11d, echo=F, warning=F}

plot1<- Cons22 %>%
  ggplot(aes(x = fct_infreq(brexitID), fill=brexitID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Has a Brexit identity?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

plot2<- Cons22 %>%
  ggplot(aes(x = fct_infreq(partyID), fill=partyID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format(), limits = c(0,1))+
  ylab("")+
  xlab("")+
  ggtitle("Has a party identity?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))


plot3<- Cons22 %>%
  ggplot(aes(x = fct_infreq(doubleID), fill=doubleID)) +
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  scale_y_continuous(labels = scales::percent_format())+
  ylab("Proportion of respondents")+
  xlab("")+
  ggtitle("Has both identities?")+
  theme_minimal() +
  scale_fill_manual(values=colors, name="")+
  theme(legend.position = "none")+
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10))

(plot1+plot2)/plot3+
  plot_annotation(title = "Prevalence of party & issue identities among\n2019 Conservative voters (May 2022)",
                  caption = "Data: British Election Study Internal Panel Wave 23 (N=11,552)",
                  theme=theme(plot.title=element_text(size = 16, face="bold", hjust=0)))
ggsave("output/FigureA11d.png", width =24, height = 19, units = "cm", dpi=600)


```
